package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class cls = Class.forName("reflect.Teacher");
        Object o = cls.newInstance();
        /*
            Field类，它也是反射对象之一
            它的每一个实例用于表示类中的某个属性
         */
        //获取Teacher类的name属性
        Field field = cls.getField("name");
        field.set(o,"范传奇");
        System.out.println(o);
    }
}
